<template>
  <div class="app-container">
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">基本信息</span>
    </div>
    <div class="table-layout">
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >服务名称</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >分类</el-col>
        <el-col
          :span="12"
          class="table-cell-title"
        >副标题</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.specName }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.serverSpecName }}</el-col>
        <el-col
          :span="12"
          class="table-cell"
        >{{ course.specDesc }}</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >品类</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
          style="height:37px"
        >上门服务时间段1</el-col>
        <el-col
          :span="12"
          class="table-cell-title"
          style="height:37px"
        >上门服务时间段2</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell"
          style="font-size: 13px"
        >{{ course1.name }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{(tempValue[0] && tempValue[0].time) || "" }}</el-col>
        <el-col
          :span="12"
          class="table-cell"
        >{{(tempValue[1] && tempValue[1].time) || ""  }}
        </el-col>
      </el-row>
    </div>
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">属性列表</span>
    </div>
    <div class="table-layout">
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >属性名</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >类型</el-col>
        <el-col
          :span="12"
          class="table-cell-title"
        >属性值</el-col>
      </el-row>
      <el-row
        v-for="(item,index) in list"
        :key="index"
      >
        <el-col
          :span="6"
          class="table-cell"
        >{{ item.prptyNameShow }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ prptyType[item.prptyType] }}</el-col>
        <el-col
          :span="12"
          class="table-cell"
        >{{ item.prptyValue }}</el-col>
      </el-row>
    </div>
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">规格价格</span>
    </div>
    <div style="margin-top: 20px">
      <el-table
        border
        :data="course.skuTableData"
        style="width: 100%"
      >
        <el-table-column
          v-for="(item,i) in course.skuListLabel"
          :key="i"
          :prop="item.prop"
          :label="item.label"
        >
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">服务详情</span>
    </div>
    <div style="margin-top: 20px">
      <!--      <svg-icon icon-class="marker" style="color: #606266"></svg-icon>-->
      <span class="font-small">1.服务封面</span>
    </div>
    <img
      v-if="course.mainPicId"
      class="coursePic"
      :src="course.mainPicId"
      style="width:100px"
    />
    <div style="margin-top: 20px">
      <span class="font-small">2.服务详情内容</span>
    </div>
    <el-form>
      <el-form-item>
        <div v-html="course2.prodSpecDetail"></div>

      </el-form-item>
    </el-form>
    <el-row
      type="flex"
      justify="end"
      style="margin-top: 20px"
    >
      <el-col :span="2">
        <el-button @click="back">返回</el-button>
      </el-col>
    </el-row>

  </div>
</template>
<script>
import { getProdSpecById } from "@/api/servMs";
import { formatDate } from "@/utils/date";
export default {
  name: "CourseList",
  data() {
    return {
      course: {},
      course1: {},
      course2: {},
      tempValue: [],
      list2: [],
      list3: [],
      list: null,
      total: null,
      listLoading: false,
      prptyType: {
        1: "销售属性",
        2: "自然属性",
      },
      list1: [],
      prptyCode: "",
      prptyValue: "",
    };
  },
  created() {
    getProdSpecById({ prodSpecId: this.$route.query.id }).then((response) => {
      this.course = response.data;
      console.log(this.course);
      this.course1 = response.data.prprtyPackage;
      this.course2 = response.data.pmProdSpecDetail;
      this.tempValue = eval(
        "(" + response.data.prodSpecStockTempList[0].tempValue + ")"
      );
      console.log(this.tempValue);
      this.list = response.data.prprtyPackage.prptyList;
      this.list2 = response.data.skuListLabel;
      this.list3 = response.data.skuTableData;
      this.list.map((item, index) => {
        this.list1 = item.prptyValList;
        this.prptyCode = item.prptyCode;
        this.list1.map((item, index) => {
          this.prptyValue += item.prptyValue;
          if (this.list1.length - 1 !== index) {
            this.prptyValue += ";";
          }
        });
        item.prptyValue = this.prptyValue;
        this.prptyValue = "";
        // console.log(this.list1, this.list)
      });
    });
  },
  filters: {
    formatCouerseType(typeList) {
      let type = "";
      typeList &&
        typeList.map((item, index) => {
          type = type + item.name + (typeList.length === index + 1 ? "" : "/");
        });
      return type;
    },
    formatDateTime(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      const date = new Date(time);
      return formatDate(date, "yyyy-MM-dd hh:mm:ss");
    },
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scoped>
.app-container {
  width: 80%;
  margin: 20px auto;
}

.table-layout {
  margin-top: 20px;
  border-left: 1px solid #dcdfe6;
  border-top: 1px solid #dcdfe6;
}

.table-cell {
  height: 60px;
  line-height: 40px;
  border-right: 1px solid #dcdfe6;
  border-bottom: 1px solid #dcdfe6;
  padding: 10px;
  font-size: 14px;
  color: #606266;
  text-align: center;
  overflow: hidden;
}

.table-cell-title {
  border-right: 1px solid #dcdfe6;
  border-bottom: 1px solid #dcdfe6;
  padding: 10px;
  background: #f2f6fc;
  text-align: center;
  font-size: 14px;
  color: #303133;
}

.coursePic {
  margin-top: 20px;
  max-width: 100%;
}
</style>
